package merchant

import (
	"organoid_public/domain/fitness"
	service2 "organoid_public/domain/fitness/service"
)

type service struct {
	svc service2.MerchantServiceInterface
}

func NewService() (*service, error) {
	uc, err := fitness.Service()
	if err != nil {
		return nil, err
	}
	return &service{svc: uc.MerchantSvc}, err
}

func (s *service) detail(id int) DetailRep {
	info := s.svc.Detail(id)
	return DetailRep{
		Id:           info.Id,
		Phone:        info.Phone,
		MerchantPid:  info.MerchantPid,
		MerchantType: info.MerchantType,
		Name:         info.MerchantName,
		OpenAppId:    info.OpenAppId,
		Status:       info.Status,
		SaleId:       info.SaleId,
		AppAuthToken: info.AppAuthToken,
		Appid:        info.Appid,
		ShopId:       info.ShopId,
	}
}

func (s *service) upsert(params *UpInsertReq, OpenAppId string) error {
	s.svc.SaveOrInsert(&service2.SaveOrInsertParams{
		OpenAppId:      OpenAppId,
		OpenMerchantId: params.OpenMerchantId,
		MerchantName:   params.Name,
		Appid:          params.Appid,
		Phone:          params.Phone,
		ShopId:         params.ShopId,
		MerchantPid:    params.MerchantPid,
		AppAuthToken:   params.AppAuthToken,
		ReqCommitAli:   params.ReqCommitAli,
	})
	return nil
}

func (s *service) bindStore(params *BindStoreReq) error {
	err := s.svc.BindStore(*params)
	return err
}
